﻿using System.Threading.Tasks;
using FytSoa.Common;
using FytSoa.Core.Model.Member;
using FytSoa.Core.Model.Sw;
using FytSoa.Service.DtoModel;
using FytSoa.Service.Extensions;
using FytSoa.Service.Interfaces;
using SqlSugar;
namespace FytSoa.Service.Implements
{
    /*!
    * 文件名称：Sw_couponlog服务接口实现
    */
    public class Sw_couponlogService : BaseServer<Sw_couponlog>, ISw_couponlogService
    {
        /// <summary>
        /// 查询日志列表
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public async Task<ApiResult<Page<Sw_couponlog>>> GetPageCouponLog(PageParm param)
        {
            var res = new ApiResult<Page<Sw_couponlog>>() { statusCode = (int)ApiEnum.Error };
            try
            {
                res.data = await Db.Queryable<Sw_couponlog,Member>((s,m)=>new JoinQueryInfos(
                        JoinType.Left,s.MemberGuid==m.Guid
                    ))
                    .WhereIF(!string.IsNullOrEmpty(param.guid), (s, m) => s.CouponGuid==param.guid)
                    .OrderBy((s, m) => s.IsUse, OrderByType.Desc)
                    .Select<Sw_couponlog>()
                    .ToPageAsync(param.page, param.limit);
                res.statusCode = (int)ApiEnum.Status;
            }
            catch (System.Exception ex)
            {
                res.message = ex.Message;
            }
            return res;
        }
    }
}